package com.miniits.base.all;

import com.miniits.base.utils.BaseController;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: wq
 * @Date: 2018/4/10
 * @Time: 14:58
 * <p>
 * Description:
 * ***
 */
@Controller
@RequestMapping("crawler")
public class BetController extends BaseController {

    public final static String T_U = "https://7697-36.com";
    public final static Map<String, User> users = new HashMap<String, User>() {{
        put("1", new User("xizang001", "123456"));
        put("2", new User("xizang002", "123456"));
        put("3", new User("xizang003", "123456"));
        put("4", new User("xizang004", "123456"));
        put("5", new User("qwe000", "qwe000"));
    }};

    @Autowired
    private BetPull betPull;

    @Autowired
    private BetService betService;

    @PostMapping("/gys")
    @ResponseBody
    public String gys(Bet bet) {
        betService.saves(bet);
        return "ok";
    }

    @GetMapping("/get")
    @ResponseBody
    public Bet get() {
        List<Bet> bets = betService.findAll();
        if (bets.size() >= 1) {
            return bets.get(0);
        }
        return new Bet(1000);
    }

    @GetMapping("36")
//    @Scheduled(cron = "0 0 12 * * ? ")
    @Scheduled(cron = "0 40 11 * * ? ")
    public void s() throws InterruptedException {
        long curr = System.currentTimeMillis();

        for (int i = 1; i <= 5; i++) {
            try {
                betPull.startRun(curr, String.valueOf(i));
            } catch (Exception e) {
            }
            Thread.sleep(30 * 1000);
        }

    }
}
